//
//  JMHomeOrderView.m
//  NewiOSProject
//
//  Created by JMMac on 25.12.23.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMHomeOrderView.h"
#import "JMOrderInfoVC.h"
@interface JMHomeOrderView()
@property (nonatomic, strong)NSMutableArray *repaidOrders;
@end

@implementation JMHomeOrderView

-(instancetype)initWithFrame:(CGRect)frame andModelArray:(NSArray<JMOrderModel*> *)modelArray{
    if (self = [super initWithFrame:frame]) {
        self.repaidOrders = @[].mutableCopy;
        [self.repaidOrders addObjectsFromArray:modelArray];
        
        UILabel *soloLab = [JMControl createLabelWithFrame:(CGRectMake(0, 24, 150, 24)) Font:fontWithWeight(17, UIFontWeightMedium) Text:@"Aumentar la cuota" color:Hex_Str_COLOR(@"#222222")];
        [self addSubview:soloLab];
        soloLab.backgroundColor = WhiteColor();
        soloLab.textAlignment = 1;
        soloLab.centerX = kAppW()/2;
        
        UIView *lineV = [[UIView alloc]initWithFrame:(CGRectMake(0, 0, 198, 2))];
        lineV.backgroundColor = Hex_Str_COLOR(@"#3C57F8");
        [self addSubview:lineV];
        [self sendSubviewToBack:lineV];
        lineV.center = soloLab.center;
        CGFloat w = CalculateLabelWidthWithLab(soloLab);
        soloLab.width = w;
        soloLab.centerX = kAppW()/2;
        lineV.width = w+16+48;
        lineV.centerX = soloLab.centerX;
        
        CGFloat top = soloLab.bottom+16;
        NSInteger i=0;
        for (int i=0; i<modelArray.count; i++) {
            
            JMOrderModel*model = modelArray[i];
            UIImageView *coinImg = [[UIImageView alloc]initWithFrame:(CGRectMake(24, top, 36, 36))];
            [coinImg sd_setImageWithURL:URLImageWithUrlStr(model.slogan) placeholderImage:nil];
            [self addSubview:coinImg];
            
            UILabel *topTitleLab = [JMControl createLabelWithFrame:(CGRectMake(coinImg.right+12, coinImg.bottom+12, kAppW(), FontH(17))) Font:BoldFont(15) Text:model.productName color:Text_COLOR_LEVEL1()];
            topTitleLab.centerY = coinImg.centerY;
            [self addSubview:topTitleLab];
          
            
            UILabel *subTitleLab = [JMControl createLabelWithFrame:(CGRectMake(coinImg.left, coinImg.bottom+12, kAppW()-180, 40)) Font:Font(14) Text:@"Cuota posterior al reembolso +400~1000" color:Hex_Str_COLOR(@"#555555")];
            [self addSubview:subTitleLab];
            [JMControl changeTextColorWithLabel:subTitleLab changeStr:@"+400~1000" color:mainSchemeColor()];
            
            UIButton *modificarBtn = [JMControl createButtonWithFrame:(CGRectMake(subTitleLab.right+12, subTitleLab.top, 120, 32)) Target:self Action:@selector(modificarBtnClick:) Title:@"Ir a desembolsar" titlColor:Hex_Str_COLOR(@"#ffffff") font:Font(12) tag:i backgroundColor:GradientColorWithColor((CGRectMake(subTitleLab.right+12, subTitleLab.top, 120, 32).size), FXGradientChangeDirectionHorizontal, mainStartColor(), mainEndColor())];
            [self addSubview:modificarBtn];
            modificarBtn.cornerRadius = 16;
            modificarBtn.centerY = subTitleLab.centerY;
            
            top = subTitleLab.bottom+16;
            i+=1;
        }
        
        self.height = top;

    }
    return self;
}
-(void)modificarBtnClick:(UIButton *)sender{
    JMOrderInfoVC *vc= JMOrderInfoVC.new;
    vc.listModel = self.repaidOrders[sender.tag-1];
    [self.viewController.navigationController pushViewController:vc animated:YES];
}
@end
